import BaseStore from "@/base/BaseStore";

const StatusLabel = {
    1: "待支付",
    2: "已支付",
    4: "已退款"
}
export default class Store extends BaseStore {
    constructor(props, config, action) {
        super(props, config, action)
        this.state = this.getInitialState()
    }

    getInitialSo() {
        return {
            status:""
        }
    }

    doAfterSearchCompleted() {
        let {so} = this.state;
        if (!so.searchByStatus) {
            this.Action.statusCount(this.state.so);
            so.searchByStatus = false;
            this.setState({so});
        }

    }

    onStatusCount() {
        this.setState({loading: true});
    }

    onStatusCountCompleted(res) {
        this.setState({loading: false});
        super.dealResponse(res, () => {
            let {voList = []} = res;
            let total = 0;
            let statusMap = {};
            voList.forEach(o => {
                let {status, count} = o;
                statusMap[status] = count;
                total += count;
            })
            let statusList = [{value: "", label: "全部", count: total}];
            for (let s in StatusLabel) {

                statusList.push({label: StatusLabel[s], value: s, count: statusMap[s] || 0})

            }

            this.setState({statusList})
        })
    }

    onPreRefund() {
        this.setState({modalStatus: "refund"});
    }

    onRefund() {
        this.setState({detailLoading: true});
    }

    onRefundCompleted(callback, res) {
        this.setState({detailLoading: false});
        super.dealCommonResponse(res,()=>{
            callback && callback();
        });

    }

}